package com.luck.easyfoodbatch.mvp.mine;

import android.content.Context;
import android.support.annotation.Nullable;

import com.luck.easyfoodbatch.callback.JsonCallback;
import com.luck.easyfoodbatch.entity.FeedBack;
import com.luck.easyfoodbatch.util.HttpUtil;
import com.lzy.okhttputils.OkHttpUtils;
import com.lzy.okhttputils.cache.CacheMode;
import com.lzy.okhttputils.model.HttpParams;

import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;

/**
 * author：luck
 * project：LoveCare
 * package：com.tongyu.luck.lovecare.mvp.login
 * email：893855882@qq.com
 * data：16/8/10
 */
public class FeedBackPresenter implements FeedbackModel {
    private final String TAG = "FeedBackPresenter";
    private FeedbackView feedbackView;
    private Context mContext;

    public FeedBackPresenter(FeedbackView feedbackView, Context mContext) {
        this.feedbackView = feedbackView;
        this.mContext = mContext;
    }


    @Override
    public void postSuggestion(String content, String images) {
        HttpParams params = new HttpParams();
        params.put("content", content);
        params.put("images", images);
        OkHttpUtils.post(HttpUtil.SUGGESTION)
                .tag(this)
                .cacheMode(CacheMode.DEFAULT)// 缓存模式
                .cacheKey(TAG)
                .params(params)
                .execute(new JsonCallback(mContext, FeedBack.class) {

                    @Override
                    public void onResponse(boolean isFromCache, Object data, Request request, @Nullable Response response) {
                        feedbackView.submitFeedbackSuccess((FeedBack) data);
                        feedbackView.hideLoading();
                    }

                    @Override
                    public void onError(boolean isFromCache, Call call, @Nullable Response response, @Nullable Exception e) {
                        super.onError(isFromCache, call, response, e);
                        feedbackView.hideLoading();
                    }
                });
    }
}
